/**
 * Copyright (c) 2011 - 2012, Sohu Inc. All rights reserved.
 * @fileoverview Sohu  用户管理页
 * @author  wangxin | xinwang200110@sohu-inc.com
 * @version 1.0 | 2013-04-17
 * @param
 * @example
 */

$require('cpt.LJSDefine');
$require('cpt.search');
$require('cpt.allSelect');
$require('cpt.addUser');
$require('cpt.addUserList');
$require('mod.cAlert');
LJS.define('page.userManage',function(ljs){
   //搜索部分初始化
   ljs.cpt.search.init();
   
   //全选、删除功能初始化
   ljs.cpt.allSelect.init();
   
   
   // 添加用户功能初始化
   ljs.cpt.addUser.init();
   
   // 添加到组初始化
   ljs.cpt.addUser.init();
   $('[event_type="addGroups"]').on('click',function(){
		var eleArr = $('[form-type="check"]:checked'),arr = [];											 
		$.each(eleArr, function(i, ele){
                if (ele.checked) {
                    ele.checked = true;
                    arr.push(ele.getAttribute('form-data'));
                }
            });								 
		if(arr.length!=0){
			ljs.cpt.addUserList.showAdd(arr)
		}else{
			ljs.mod.cAlert({txt:'没有选中项'})
			}									 
	})
   $('[event_type="addGroup"]').on('click',function(){
			ljs.cpt.addUserList.showAdd([$(this).attr('id')])
	 })
   $('#userGroups').on('change',function(){
										 window.location.reload();
										 })
   
   $('[event_type="forbidden"]').on('click',function(){
	   var id = $(this).attr('id');
	   var text = $(this).text();
	   var action = '';
	   if ('禁用' == text) {
		   action = 'forbid';
	   } else if ('启用' == text) {
		   action = 'start';
	   }
	   
	   var that = {};
	   that.layer = ljs.mod.cPrompt({
           tpl: '<div class="infor"><div class="title"><span class="txt">信息提示</span><span class="btnExit"><a href="javascript:void(0);" event_type="del"></a></span></div><dl class="conTxt"><dt><span>您确定要'+text+'该用户吗？</span></dt>\
           </dl><div class="btnEn"><a class="btn-et" href="javascript:void(0);" event_type="ok"><span>确定</span></a><a class="btn-ex" href="javascript:void(0);" event_type="del"><span>取消</span></a></div></div>',
           caClose: true,
           txt: '',
           btnTxt: '确定',
           fun: function(){
        	   that.layer.del();
       		$.ajax({
       			  type: "post",
       			  url: "user_forbidden/",
       			  dataType: "json",
       			  data:{id:id, action:action},
       			  cache:false,
       			  success:function(json){
       				  if(json.status == '100000'){
       					  window.location.reload();
       				  }else{
       					  ljs.mod.cAlert({txt: text + '失败'})
       					  }
       			      }
       			});
           }
       });
	 })
  
});